{% init file = None %}
{% init can_edit = False %}

<span>标签</span>
{% if len(file.tags) == 0 %}
    <span>(无)</span>
{% end %}

{% for tag_name in file.tags %}
    <a class="tag lightgray large" href="/note/{{file.parent_id}}?tag={{quote(tag_name)}}">{{tag_name}}</a>
{% end %}

<div class="float-right">
    {% if can_edit %}
        <button class="btn btn-default tag-edit-btn">编辑</button>
    {% end %}
</div>


<div class="hide">
<!-- 这个功能使用频率太低了 -->
{% if file != None %}

    {% if file.priority == 1 %}
        <a class="tag system" href="/note/sticky">置顶</a>
    {% end %}

    {% if file.type == "list" %}
        <a class="btn btn-default" href="/note/list">清单</a>
    {% end %}

    {% if file.type in ("csv", "table") %}
        <a class="btn btn-default" href="/note/table">表格</a>
    {% end %}

    {% if file.type == "gallery" %}
        <a class="btn btn-default" href="/note/gallery">相册</a>
    {% end %}

    {% if file.type == "html" %}
        <a class="btn btn-default" href="/note/html">富文本</a>
    {% end %}

    {% if file.type == "log" %}
        <a class="btn btn-default" href="/note/log">日志</a>
    {% end %}

    {% if file.type in ("md", "text", "plan") %}
        <a class="tag system" href="/note/document">文档</a>
    {% end %}

    {% if file.is_public %}
        <a class="btn btn-default" href="/note/public">公开</a>
    {% end %}

{% end %}
</div>

{% include note/component/script/tag_script.html %}

<input type="hidden" id="noteTagJson" value="{{file.tags_json}}"/>

<script type="text/javascript">
$(".tag-edit-btn").click(function () {
    var listParams = {
        tag_type:"note",
        group_id:"{{file.parent_id}}",
    };

    $.get("/note/tag/list", listParams, function (resp) {
        var tagsJson = $("#noteTagJson").val();
        var cmd = {
            tagType: "note",
            currentTags: JSON.parse(tagsJson),
            noteId: "{{file.id}}",
            manageLink: "/note/manage?parent_id={{file.parent_id}}",
        };
        cmd.tagList = resp.data;
        // 调用绑定标签组件
        xnote.api.note.bindTag(cmd);
    })
});
</script>